package global

import (
	"github.com/sirupsen/logrus"
	"hcy-api/structs/tables"
)

func autoMigrate() {
	type vector[T any] []T
	var li = vector[interface{}]{
		&tables.IdpClient{},
		&tables.IdpClientLog{},
		&tables.IdpLogCpu{},
		&tables.IdpLogMemory{},
		&tables.IdpLogDisk{},
		&tables.IdpLogBoard{},
		&tables.IdpLogApp{},
		&tables.IdpAppChangeLog{},
		&tables.IdpLogSysAbstract{},
		&tables.IdpWarnHostname{},
		&tables.IdpWarnLoad{},
		&tables.IdpBranch{},
		&tables.IdpMapBranchUser{},
		&tables.IdpMapBranchClient{},
		&tables.IdpTask{},
		&tables.IdpTaskResult{},
		&tables.IdpOfficePoint{},
	}
	for _, item := range li {
		if !DB.Migrator().HasTable(item) {
			err := DB.AutoMigrate(item)
			if err != nil {
				logrus.Errorf("初始化数据库表结构异常: %v", err)
			}
		}
	}
}
